<?php

/*
 * 
 *    返回一个日历
 */

function getMyDate($event_arr)
{
	
	$nowinfo = getdate();
	$y = $nowinfo['year'];
	$m = $nowinfo['mon'];
	$today = $nowinfo['mday'];
	
	$n = $today-1;
	$d = strtotime("-$n day");
	$t = getdate($d);
	
	$no1 = $t['wday'];
	
	$mon31 = array('1','3','5','7','8','10','12');
	$mon30 = array('4','6','9','11');
	
	if(in_array($m,$mon30))
	{
		$monNum = 30;
	}
	if(in_array($m,$mon31))
	{
		$monNum = 31;
	}
	if(empty($monNum)){
		if(($y%4==0)&&($y%100!=0)&&($y%400==0)){
			$monNum = 29;
		}else{
			$monNum = 28;
		}
	}
	
	
	$dat = '<tr>';
	for($i=0;$i<$no1;$i++)
	{
	if($no1 == 0){
	break;
	}
	$dat.= '<td>.</td>';
    }
	
	for($j=1; $j<=$monNum; $j++)
	{
		if(($j+$no1-1)%7 == 0)
		{
			$dat.= '</tr><tr>';
  	    }
		if($j == $today)
		{
			$dat.= '<td class="today">'.$j.'</td>';
	  	}else{
						
	  		if(in_array("$j",$event_arr))
	  		{
	  			$dat.= '<td class="event">'.$j.'</td>';
	  		}else{
	  		   $dat.= '<td class="">'.$j.'</td>';
	  		}
		}
   }
	
	  $dat.= '</tr>';
	
	  return $dat;
}